package edu.utexas.mapreduce;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SharedMapState {

	// Using ConcurrentMap because it has serialization built in.
    // <key/jobid, value/object>
	private static Map <Integer, JobThread> sharedMap = 
		new ConcurrentHashMap<Integer, JobThread>();


	// add an entry to the Map
	void insertJob(Integer jobId, JobThread jobThread) {
		sharedMap.put(jobId, jobThread);
	}
		
	// remove a map entry by jobId
	void removeJobIdEntry(Integer jobId) {
		sharedMap.remove(jobId);
	}
	
	// get the thread owning a jobId
	JobThread getJobThread(Integer jobId) {
		return sharedMap.get(jobId);
	}
	
	List<Integer> getJobIDs() {
		List<Integer> list = new ArrayList<Integer>(sharedMap.size());
		list.addAll(sharedMap.keySet());
		return list;
	}
}
